// querynozzleparamdlg.cpp : implementation file
//

#include "stdafx.h"
#include "querynozzleparamdlg.h"
#include "StraightNozzle.h"
#include "CurvingNozzle.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// QueryNozzleParamDlg dialog


QueryNozzleParamDlg::QueryNozzleParamDlg(CWnd* pParent /*=NULL*/)
	: CDialog(QueryNozzleParamDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(QueryNozzleParamDlg)
	m_dEditInnerRadius = 0.0;
	m_dEditCurvousRadius = 0.0;
	m_strEditFaceType = _T("");
	m_strEditHeatPreserveType = _T("");
	m_dEditLengthFirst = 0.0;
	m_dEditLengthSec = 0.0;
	m_strEditNozzleID = _T("");
	m_strEditNozzleName = _T("");
	m_strEditNozzleType = _T("");
	m_strEditPipeID = _T("");
	m_strEditPipeRank = _T("");
	//}}AFX_DATA_INIT
}


void QueryNozzleParamDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(QueryNozzleParamDlg)
	DDX_Control(pDX, IDC_NOZZLE_PICTURE, m_Nozzle_Picture);
	DDX_Text(pDX, IDC_EDIT_INNER_RADIUS, m_dEditInnerRadius);
	DDV_MinMaxDouble(pDX, m_dEditInnerRadius, 0., 100000.);
	DDX_Text(pDX, IDC_EDIT_CURVOUS_RADIUS, m_dEditCurvousRadius);
	DDV_MinMaxDouble(pDX, m_dEditCurvousRadius, 0., 1000000.);
	DDX_Text(pDX, IDC_EDIT_FACE_TYPE, m_strEditFaceType);
	DDV_MaxChars(pDX, m_strEditFaceType, 255);
	DDX_Text(pDX, IDC_EDIT_HEAT_PRESERVE_TYPE, m_strEditHeatPreserveType);
	DDV_MaxChars(pDX, m_strEditHeatPreserveType, 255);
	DDX_Text(pDX, IDC_EDIT_LENGTH_FIRST, m_dEditLengthFirst);
	DDV_MinMaxDouble(pDX, m_dEditLengthFirst, 0., 1000000.);
	DDX_Text(pDX, IDC_EDIT_LENGTH_SEC, m_dEditLengthSec);
	DDX_Text(pDX, IDC_EDIT_NOZZLE_ID, m_strEditNozzleID);
	DDV_MaxChars(pDX, m_strEditNozzleID, 255);
	DDX_Text(pDX, IDC_EDIT_NOZZLE_NAME, m_strEditNozzleName);
	DDV_MaxChars(pDX, m_strEditNozzleName, 255);
	DDX_Text(pDX, IDC_EDIT_NOZZLE_TYPE, m_strEditNozzleType);
	DDV_MaxChars(pDX, m_strEditNozzleType, 255);
	DDX_Text(pDX, IDC_EDIT_PIPE_ID, m_strEditPipeID);
	DDV_MaxChars(pDX, m_strEditPipeID, 255);
	DDX_Text(pDX, IDC_EDIT_PIPE_RANK, m_strEditPipeRank);
	DDV_MaxChars(pDX, m_strEditPipeRank, 255);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(QueryNozzleParamDlg, CDialog)
	//{{AFX_MSG_MAP(QueryNozzleParamDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// QueryNozzleParamDlg message handlers

BOOL QueryNozzleParamDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	StdString strTmp1,strTmp2;
	strTmp1.LoadString(STRAIGHTNOZZLE);
	strTmp2.LoadString(CURVINGNOZZLE);
	if (m_strEditNozzleType == strTmp1)
	{
		HANDLE hb = ::LoadImage(NULL, "c:\\2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
		this->m_Nozzle_Picture.SetBitmap((HBITMAP)hb);
	}
	else if (m_strEditNozzleType == strTmp2)
	{
		HANDLE hb = ::LoadImage(NULL, "c:\\1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
		this->m_Nozzle_Picture.SetBitmap((HBITMAP)hb);
	}
	// TODO: Add extra initialization here
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void QueryNozzleParamDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void QueryNozzleParamDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void QueryNozzleParamDlg::SetParam(Nozzle *pNozzle)
{
	ASSERT(pNozzle);

	this->m_dEditInnerRadius = pNozzle->GetDiameter();
	this->m_strEditFaceType = pNozzle->GetEndType();
	this->m_strEditNozzleID = pNozzle->GetNozzleID();
	this->m_strEditPipeID = pNozzle->GetPipeID();
	this->m_strEditPipeRank = pNozzle->GetRank();
	this->m_strEditNozzleName = pNozzle->GetNozzleName();
	if (dynamic_cast<StraightNozzle*>(pNozzle))
	{
		this->m_strEditNozzleType.LoadString(STRAIGHTNOZZLE);
	}
	else if (dynamic_cast<CurvingNozzle*>(pNozzle))
	{
		this->m_strEditNozzleType.LoadString(CURVINGNOZZLE);
	}
	else
	{
		ASSERT(FALSE);
	}
	this->m_strEditHeatPreserveType = pNozzle->GetHeatPreserveType();
	
	if (StraightNozzle* pSNozzle = dynamic_cast<StraightNozzle*>(pNozzle))
	{
		this->m_dEditLengthFirst = pSNozzle->GetLength();
	}
	else if (CurvingNozzle* pCNozzle = dynamic_cast<CurvingNozzle*>(pNozzle))
	{
		this->m_dEditLengthFirst = pCNozzle->GetPrimaryLength();
		this->m_dEditLengthSec = pCNozzle->GetSecondaryLength();
		this->m_dEditCurvousRadius = pCNozzle->GetCurvousRadius();
	}
}
